var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var n in e) e.hasOwnProperty(n) && (t[n] = e[n]);
    })(t, e);
}, function(t, e) {
    function n() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (n.prototype = e.prototype, 
    new n());
}), a = this && this.__decorate || function(t, e, n, o) {
    var i, s = arguments.length, a = s < 3 ? e : null === o ? o = Object.getOwnPropertyDescriptor(e, n) : o;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(t, e, n, o); else for (var r = t.length - 1; 0 <= r; r--) (i = t[r]) && (a = (s < 3 ? i(a) : 3 < s ? i(e, n, a) : i(e, n)) || a);
    return 3 < s && a && Object.defineProperty(e, n, a), a;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("MyScrollView"), s = e("Global"), c = e("SkinItemView"), l = e("HpView"), d = e("SkinView"), u = e("AudioManager"), p = e("PersonView"), h = e("GameConfig"), f = e("GameData"), g = e("RoleManager"), m = e("DataManager"), y = e("LoadManager"), v = e("UIManager"), w = e("WebManager"), b = cc._decorator, P = b.ccclass, I = b.property, G = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.changeBtn = null, t.buyBtn = null, t.diamondSprite = null, t.diamondLabel = null, 
        t.personView = null, t.atkLabel = null, t.speLabel = null, t.ranLabel = null, t.criLabel = null, 
        t.movLabel = null, t.numLabel = null, t.up = null, t.down = null, t.rankLabel = null, 
        t.hpView = null, t.nums = [], t.ups = [], t.downs = [], t.numPool = new cc.NodePool(), 
        t.upPool = new cc.NodePool(), t.downPool = new cc.NodePool(), t.idx = 0, t;
    }
    return i(t, e), t.prototype.onLoad = function() {
        this.idx = f.GD.personIdx, this.refresh(this.idx);
    }, t.prototype.onEnable = function() {
        this.show(this.idx);
    }, t.prototype.onDisable = function() {
        this.removeAll();
    }, t.prototype.onClickChange = function() {
        u.default.getInstance().playAudio("按钮2"), w.default.getInstance().sentLog("点击皮肤界面替换上阵按键"), 
        f.GD.personIdx != this.idx && (-1 < f.GD.skins.indexOf(f.GD.personIdx) && (f.GD.lastPersonIdx = f.GD.personIdx), 
        f.GD.skins.indexOf(this.idx) < 0 && (s.G.tryPersonIdx = this.idx), f.GD.personIdx = this.idx, 
        this.refresh(f.GD.personIdx), this.changeBtn.interactable = !1, this.removeAll());
    }, t.prototype.onClickBuy = function() {
        var t, e;
        u.default.getInstance().playAudio("按钮2"), w.default.getInstance().sentLog("点击皮肤界面购买按键");
        var n = -1 < this.idx && this.idx < h.GC.skinCostList.length ? h.GC.skinCostList[this.idx] : {
            id: this.idx,
            type: 0,
            num: s.G.getPersonModel(this.idx).price
        };
        switch (n.type) {
          case 0:
            if (f.GD.diamond < n.num) return void (s.G.platform != s.Platform.XiaoDu ? v.default.getInstance().loadPopPnl("diamond", {
                num: 100,
                view: this
            }) : v.default.getInstance().showToast({
                str: "钻石不足"
            }));
            f.GD.diamond -= n.num, f.GD.addSkin(this.idx) && (v.default.getInstance().barViews.forEach(function(t) {
                return t.refresh();
            }), m.default.getInstance().upload({
                json: !0,
                local: !0,
                skin: this.idx
            }));
            break;

          case 1:
            if (f.GD.piece < n.num) return void (f.GD.pieceCount < h.GC.maxPieceCount && s.G.platform != s.Platform.XiaoDu ? v.default.getInstance().loadPopPnl("piece", {
                num: h.GC.pieceNum,
                view: this
            }) : GA.PA && GA.PA.showToast ? null === (e = null === (t = GA.PA) || void 0 === t ? void 0 : t.showToast) || void 0 === e || e.call(t, {
                title: "碎片不足",
                icon: "none"
            }) : v.default.getInstance().showToast({
                str: "碎片不足"
            }));
            f.GD.piece -= n.num, f.GD.addSkin(this.idx) && (v.default.getInstance().barViews.forEach(function(t) {
                return t.refresh();
            }), m.default.getInstance().upload({
                json: !0,
                local: !0,
                skin: this.idx
            }));
        }
        f.GD.personIdx != this.idx && (-1 < f.GD.skins.indexOf(f.GD.personIdx) && (f.GD.lastPersonIdx = f.GD.personIdx), 
        s.G.tryPersonIdx = -1, f.GD.personIdx = this.idx, this.refresh(f.GD.personIdx), 
        this.changeBtn.node.active = !0, this.changeBtn.interactable = !1, this.buyBtn.node.active = !1, 
        this.removeAll());
    }, t.prototype.onToggle = function(t) {
        t = t.getComponent(c.default).__itemID;
        this.show(s.G.personModelList[t].id);
    }, t.prototype.refresh = function(t) {
        this.idx = t, this.refreshBtn(t), this.refreshSkin(t), cc.systemEvent.emit("change_person_skin");
        var e = s.G.getPersonModel(t);
        this.rankLabel.string = e.j;
        e = -1 < t && t < h.GC.skinCostList.length ? h.GC.skinCostList[t] : {
            id: t,
            type: 0,
            num: e.price.toString()
        };
        this.diamondLabel.string = e.num.toString(), this.setValue(this.getValue(this.checkPersonIdx(t), t)), 
        this.refreshLabel();
    }, t.prototype.show = function(t) {
        var e = this;
        this.idx = t, this.refreshBtn(t), this.refreshSkin(t), this.removeAll();
        var n = s.G.getPersonModel(t);
        this.rankLabel.string = n.j;
        var o = -1 < t && t < h.GC.skinCostList.length ? h.GC.skinCostList[t] : {
            id: t,
            type: 0,
            num: n.price.toString()
        };
        switch (o.type) {
          case 0:
            y.default.getInstance().loadSpriteFrame({
                url: "image/ui/钻石2@2x",
                sprite: this.diamondSprite,
                success: function() {
                    e.diamondSprite.node.scale = 1;
                }
            }), this.buyBtn.interactable = !0, this.diamondLabel.string = o.num.toString();
            break;

          case 1:
            y.default.getInstance().loadSpriteFrame({
                url: "image/ui/碎片@2x",
                sprite: this.diamondSprite,
                success: function() {
                    e.diamondSprite.node.scale = .4;
                }
            }), this.buyBtn.interactable = !0, this.diamondLabel.string = o.num.toString();
            break;

          case 2:
            y.default.getInstance().loadSpriteFrame({
                url: "image/ui/钻石2@2x",
                sprite: this.diamondSprite,
                success: function() {
                    e.diamondSprite.node.scale = 1;
                }
            }), this.buyBtn.interactable = !1, this.diamondLabel.string = "其他途径获取";
        }
        this.showLabel(this.getValue(this.checkPersonIdx(t), t));
    }, t.prototype.setValue = function(t) {
        g.default.getInstance().value = t;
    }, t.prototype.getValue = function(t, e) {
        var n = g.default.getInstance().getAtk(t, e), o = 10 * Math.floor(10 / g.default.getInstance().getSpe(t, e)), i = g.default.getInstance().getRan(t), s = g.default.getInstance().getCri(t, e), a = g.default.getInstance().getMove(t, e), e = g.default.getInstance().getHp(t, e);
        return new d.SkinItemValue(n, o, i, s, a, e);
    }, t.prototype.refreshLabel = function(t) {
        void 0 === t && (t = g.default.getInstance().value), this.atkLabel.string = t.atk.toString(), 
        this.speLabel.string = t.spe.toString(), this.ranLabel.string = t.ran.toString(), 
        this.criLabel.string = t.cri + "%", this.movLabel.string = t.mov.toString(), this.hpView.init(t.hp);
    }, t.prototype.showLabel = function(t) {
        void 0 === t && (t = g.default.getInstance().value), this.refreshLabel(t), t.atk != g.default.getInstance().value.atk && this.append(t.atk - g.default.getInstance().value.atk, this.atkLabel.node.parent), 
        t.spe != g.default.getInstance().value.spe && this.append(t.spe - g.default.getInstance().value.spe, this.speLabel.node.parent), 
        t.ran != g.default.getInstance().value.ran && this.append(t.ran - g.default.getInstance().value.ran, this.ranLabel.node.parent), 
        t.cri != g.default.getInstance().value.cri && this.append(t.cri - g.default.getInstance().value.cri, this.criLabel.node.parent), 
        t.mov != g.default.getInstance().value.mov && this.append(t.mov - g.default.getInstance().value.mov, this.movLabel.node.parent);
    }, t.prototype.refreshBtn = function(t) {
        t == f.GD.personIdx ? (this.changeBtn.node.active = !0, this.changeBtn.interactable = !1, 
        this.buyBtn.node.active = !1) : -1 < f.GD.skins.indexOf(t) || s.G.tryPersonMap.has(s.G.tryPersonIdx) && s.G.tryPersonMap.get(s.G.tryPersonIdx).time > Date.now() ? (this.changeBtn.node.active = !0, 
        this.changeBtn.interactable = !0, this.buyBtn.node.active = !1) : (this.changeBtn.node.active = !1, 
        this.buyBtn.node.active = !0);
    }, t.prototype.refreshSkin = function(t) {
        this.personView.init(t, this.checkPersonIdx(t)), cc.systemEvent.emit("refresh_person_skin");
    }, t.prototype.checkPersonIdx = function(t) {
        return 2001 == f.GD.gunIdx ? 3 == t || 9 == t ? f.GD.gunIdx : f.GD.topRank : 1008 != f.GD.gunIdx || -17 == t ? f.GD.gunIdx : f.GD.topRank;
    }, t.prototype.append = function(t, e) {
        var n, o = this.getNum();
        o.parent = e, o.setPosition(cc.v2(200, 0)), this.nums.push(o), 0 < t ? (o.color = cc.Color.GREEN, 
        o.getComponent(cc.Label).string = "+" + t, (n = this.getUp()).parent = e, n.setPosition(cc.v2(250, 0)), 
        this.ups.push(n)) : (o.color = cc.Color.RED, o.getComponent(cc.Label).string = "" + t, 
        (t = this.getDown()).setPosition(cc.v2(250, 0)), t.parent = e, this.downs.push(t));
    }, t.prototype.removeAll = function() {
        for (;0 < this.nums.length; ) this.numPool.put(this.nums.pop());
        for (;0 < this.ups.length; ) this.upPool.put(this.ups.pop());
        for (;0 < this.downs.length; ) this.downPool.put(this.downs.pop());
    }, t.prototype.getNum = function() {
        return 0 < this.numPool.size() ? this.numPool.get() : cc.instantiate(this.numLabel.node);
    }, t.prototype.getUp = function() {
        return 0 < this.upPool.size() ? this.upPool.get() : cc.instantiate(this.up);
    }, t.prototype.getDown = function() {
        return 0 < this.downPool.size() ? this.downPool.get() : cc.instantiate(this.down);
    }, a([ I(cc.Button) ], t.prototype, "changeBtn", void 0), a([ I(cc.Button) ], t.prototype, "buyBtn", void 0), 
    a([ I(cc.Sprite) ], t.prototype, "diamondSprite", void 0), a([ I(cc.Label) ], t.prototype, "diamondLabel", void 0), 
    a([ I(p.default) ], t.prototype, "personView", void 0), a([ I(cc.Label) ], t.prototype, "atkLabel", void 0), 
    a([ I(cc.Label) ], t.prototype, "speLabel", void 0), a([ I(cc.Label) ], t.prototype, "ranLabel", void 0), 
    a([ I(cc.Label) ], t.prototype, "criLabel", void 0), a([ I(cc.Label) ], t.prototype, "movLabel", void 0), 
    a([ I(cc.Label) ], t.prototype, "numLabel", void 0), a([ I(cc.Node) ], t.prototype, "up", void 0), 
    a([ I(cc.Node) ], t.prototype, "down", void 0), a([ I(cc.Label) ], t.prototype, "rankLabel", void 0), 
    a([ I(l.default) ], t.prototype, "hpView", void 0), a([ P ], t);
}(r.default);

n.default = G;